{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "44208717",
   "metadata": {},
   "outputs": [
    {
     "ename": "Terminator",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTerminator\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[1], line 50\u001b[0m\n\u001b[0;32m     48\u001b[0m     right(\u001b[38;5;241m120\u001b[39m)\n\u001b[0;32m     49\u001b[0m     backward(s)\n\u001b[1;32m---> 50\u001b[0m tree(\u001b[38;5;241m15\u001b[39m, n)\n\u001b[0;32m     51\u001b[0m backward(n\u001b[38;5;241m/\u001b[39m\u001b[38;5;241m2\u001b[39m)\n\u001b[0;32m     53\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(\u001b[38;5;241m200\u001b[39m):\u001b[38;5;66;03m#循环画最底端的小装饰\u001b[39;00m\n",
      "Cell \u001b[1;32mIn[1], line 44\u001b[0m, in \u001b[0;36mtree\u001b[1;34m(d, s)\u001b[0m\n\u001b[0;32m     42\u001b[0m tree(d\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m, s\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m.8\u001b[39m)\n\u001b[0;32m     43\u001b[0m right(\u001b[38;5;241m120\u001b[39m)\n\u001b[1;32m---> 44\u001b[0m tree(d\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m3\u001b[39m, s\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m.5\u001b[39m)\n\u001b[0;32m     45\u001b[0m drawlight()\u001b[38;5;66;03m#同时调用小彩灯的方法\u001b[39;00m\n\u001b[0;32m     46\u001b[0m right(\u001b[38;5;241m120\u001b[39m)\n",
      "Cell \u001b[1;32mIn[1], line 47\u001b[0m, in \u001b[0;36mtree\u001b[1;34m(d, s)\u001b[0m\n\u001b[0;32m     45\u001b[0m drawlight()\u001b[38;5;66;03m#同时调用小彩灯的方法\u001b[39;00m\n\u001b[0;32m     46\u001b[0m right(\u001b[38;5;241m120\u001b[39m)\n\u001b[1;32m---> 47\u001b[0m tree(d\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m3\u001b[39m, s\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m.5\u001b[39m)\n\u001b[0;32m     48\u001b[0m right(\u001b[38;5;241m120\u001b[39m)\n\u001b[0;32m     49\u001b[0m backward(s)\n",
      "Cell \u001b[1;32mIn[1], line 44\u001b[0m, in \u001b[0;36mtree\u001b[1;34m(d, s)\u001b[0m\n\u001b[0;32m     42\u001b[0m tree(d\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m, s\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m.8\u001b[39m)\n\u001b[0;32m     43\u001b[0m right(\u001b[38;5;241m120\u001b[39m)\n\u001b[1;32m---> 44\u001b[0m tree(d\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m3\u001b[39m, s\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m.5\u001b[39m)\n\u001b[0;32m     45\u001b[0m drawlight()\u001b[38;5;66;03m#同时调用小彩灯的方法\u001b[39;00m\n\u001b[0;32m     46\u001b[0m right(\u001b[38;5;241m120\u001b[39m)\n",
      "Cell \u001b[1;32mIn[1], line 42\u001b[0m, in \u001b[0;36mtree\u001b[1;34m(d, s)\u001b[0m\n\u001b[0;32m     40\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m d \u001b[38;5;241m<\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m: \u001b[38;5;28;01mreturn\u001b[39;00m\n\u001b[0;32m     41\u001b[0m forward(s)\n\u001b[1;32m---> 42\u001b[0m tree(d\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m, s\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m.8\u001b[39m)\n\u001b[0;32m     43\u001b[0m right(\u001b[38;5;241m120\u001b[39m)\n\u001b[0;32m     44\u001b[0m tree(d\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m3\u001b[39m, s\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m.5\u001b[39m)\n",
      "Cell \u001b[1;32mIn[1], line 47\u001b[0m, in \u001b[0;36mtree\u001b[1;34m(d, s)\u001b[0m\n\u001b[0;32m     45\u001b[0m drawlight()\u001b[38;5;66;03m#同时调用小彩灯的方法\u001b[39;00m\n\u001b[0;32m     46\u001b[0m right(\u001b[38;5;241m120\u001b[39m)\n\u001b[1;32m---> 47\u001b[0m tree(d\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m3\u001b[39m, s\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m.5\u001b[39m)\n\u001b[0;32m     48\u001b[0m right(\u001b[38;5;241m120\u001b[39m)\n\u001b[0;32m     49\u001b[0m backward(s)\n",
      "Cell \u001b[1;32mIn[1], line 42\u001b[0m, in \u001b[0;36mtree\u001b[1;34m(d, s)\u001b[0m\n\u001b[0;32m     40\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m d \u001b[38;5;241m<\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m: \u001b[38;5;28;01mreturn\u001b[39;00m\n\u001b[0;32m     41\u001b[0m forward(s)\n\u001b[1;32m---> 42\u001b[0m tree(d\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m, s\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m.8\u001b[39m)\n\u001b[0;32m     43\u001b[0m right(\u001b[38;5;241m120\u001b[39m)\n\u001b[0;32m     44\u001b[0m tree(d\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m3\u001b[39m, s\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m.5\u001b[39m)\n",
      "Cell \u001b[1;32mIn[1], line 48\u001b[0m, in \u001b[0;36mtree\u001b[1;34m(d, s)\u001b[0m\n\u001b[0;32m     46\u001b[0m right(\u001b[38;5;241m120\u001b[39m)\n\u001b[0;32m     47\u001b[0m tree(d\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m3\u001b[39m, s\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m.5\u001b[39m)\n\u001b[1;32m---> 48\u001b[0m right(\u001b[38;5;241m120\u001b[39m)\n\u001b[0;32m     49\u001b[0m backward(s)\n",
      "File \u001b[1;32m<string>:5\u001b[0m, in \u001b[0;36mright\u001b[1;34m(angle)\u001b[0m\n",
      "\u001b[1;31mTerminator\u001b[0m: "
     ]
    }
   ],
   "source": [
    "import turtle as t  #as就是取个别名，后续调用的t都是turtle\n",
    "from turtle import *\n",
    "import random as r\n",
    "import time\n",
    " \n",
    " \n",
    " \n",
    "n = 100.0\n",
    " \n",
    "speed(\"fastest\")  #定义速度\n",
    "screensize(bg='black')  #定义背景颜色，可以自己换颜色\n",
    "left(90)\n",
    "forward(3*n)\n",
    "color(\"orange\", \"yellow\")#定义最上端星星的颜色，外圈是orange，内部是yellow\n",
    "begin_fill()\n",
    "left(126)\n",
    " \n",
    "for i in range(5): #画五角星\n",
    "    forward(n/5)\n",
    "    right(144)    #五角星的角度\n",
    "    forward(n/5)\n",
    "    left(72)    #继续换角度\n",
    "end_fill()\n",
    "right(126)\n",
    " \n",
    "def drawlight():#定义画彩灯的方法\n",
    "    if r.randint(0, 30) == 0:#如果觉得彩灯太多，可以把取值范围加大一些，对应的灯就会少一些\n",
    "        color('tomato')#定义第一种颜色\n",
    "        circle(6)#定义彩灯大小\n",
    "    elif r.randint(0,30) == 1:\n",
    "        color('orange')#定义第二种颜色\n",
    "        circle(3)#定义彩灯大小\n",
    "    else:\n",
    "        color('dark green')#其余的随机数情况下画空的树枝\n",
    " \n",
    " \n",
    "color(\"dark green\")#定义树枝的颜色\n",
    "backward(n*4.8)\n",
    "def tree(d, s):#开始画树\n",
    "    if d <= 0: return\n",
    "    forward(s)\n",
    "    tree(d-1, s*.8)\n",
    "    right(120)\n",
    "    tree(d-3, s*.5)\n",
    "    drawlight()#同时调用小彩灯的方法\n",
    "    right(120)\n",
    "    tree(d-3, s*.5)\n",
    "    right(120)\n",
    "    backward(s)\n",
    "tree(15, n)\n",
    "backward(n/2)\n",
    " \n",
    "for i in range(200):#循环画最底端的小装饰\n",
    "    a = 200 - 400 * r.random()\n",
    "    b = 10 - 20 * r.random()\n",
    "    up()\n",
    "    forward(b)\n",
    "    left(90)\n",
    "    forward(a)\n",
    "    down()\n",
    "    if r.randint(0, 1) == 0:\n",
    "            color('tomato')\n",
    "    else:\n",
    "        color('wheat')\n",
    "    circle(2)\n",
    "    up()\n",
    "    backward(a)\n",
    "    right(90)\n",
    "    backward(b)\n",
    "\n",
    "t.color(\"dark red\",\"red\") #定义字体颜色\n",
    "t.write(\"Merry Christmas\",align =\"center\",font=(\"Comic Sans MS\",40,\"bold\"))#定义文字、位置、字体、大小\n",
    " \n",
    "\n",
    "def drawsnow():#定义画雪花的方法\n",
    "    t.ht()  #隐藏笔头，ht=hideturtle\n",
    "    t.pensize(2)  #定义笔头大小\n",
    "    for i in range(200): #画多少雪花\n",
    "        t.pencolor(\"white\") #定义画笔颜色为白色，其实就是雪花为白色\n",
    "        t.pu() #提笔，pu=penup\n",
    "        t.setx(r.randint(-350,350)) #定义x坐标，随机从-350到350之间选择\n",
    "        t.sety(r.randint(-100,350)) #定义y坐标，注意雪花一般在地上不会落下，所以不会从太小的纵座轴开始\n",
    "        t.pd() #落笔，pd=pendown\n",
    "        dens = 6 #雪花瓣数设为6\n",
    "        snowsize = r.randint(1,10) #定义雪花大小\n",
    "        for j in range(dens): #就是6，那就是画5次，也就是一个雪花五角星\n",
    "            #t.forward(int(snowsize))  #int（）取整数\n",
    "            t.fd(int(snowsize))\n",
    "            t.backward(int(snowsize))\n",
    "            #t.bd(int(snowsize))  #注意没有bd=backward，但有fd=forward，小bug\n",
    "            t.right(int(360/dens))  #转动角度\n",
    "\n",
    "drawsnow()#调用画雪花的方法\n",
    "t.done()  # 完成,否则会直接关闭"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "82777b68",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
